<template>
  <div class="my-train">
    <div class="mescroll"  ref="mescroll">
      <div class="classify" @click="is_mask = true">
        <p>
          <span>{{classify_name}}</span>
          <img class="classify-img" src="@/assets/shangcheng05.png" alt="">
        </p>
      </div>
      <div  class="list">
        <div class="item" v-for="(item,index) in lists" :key="index">
          <div class="left">
            <p class="title">「{{item.type_name}}」{{item.title}}</p>
            <p class="time">{{item.create_time}}</p>
          </div>
          <div class="right">
            <p class="title">{{item.num}}次</p>
            <p class="time">剩余{{item.after_num}}次</p>
          </div>
        </div>
      </div>
    </div>
    <div class="mask-div" v-if="is_mask">
      <div class="mask-bg" @click="is_mask = false"></div>
      <div class="content">
        <div class="classify" @click="classify(classifyNum, classify_name)">
          <p>
            <span>{{classify_name}}</span>
            <img class="classify-img" src="@/assets/shangcheng07.png" alt="">
          </p>
        </div>
        <div class="list-item clear">
          <div class="item" :class="(classifyNum == 0) ? 'active' : ''" @click="classify(0, '全部')">全部</div>
          <div v-for="(item,index) in cate_list" :key="index" class="item" :class="(classifyNum == item.id) ? 'active' : ''" @click="classify(item.id, item.title)">{{item.title}}</div>
        </div>
      </div>
    </div>
    <div class="none" v-show="noDate">        
      <img src="@/assets/sousuomendian04.png" alt="">
      <p>暂无相关内容</p>
    </div>
  </div>
</template>

<script>
import {mytrain,mytraincate} from '@/api/api'
import MeScroll from 'mescroll.js'
import 'mescroll.js/mescroll.min.css'
import { swiper, swiperSlide } from 'vue-awesome-swiper'
import newsList from '@/components/newsList'
import 'swiper/dist/css/swiper.css'

  export default {
    components: {
      swiper,
      swiperSlide,
      newsList
    },
    data () {
      return {
        bannerHome: {
          loop: true,
          pagination: {
            el: '.swiper-pagination',
            clickable: true
          }
        },
        classifyNum: 0,
        is_mask: false,
        classify_name: '全部',
        lists:[],
        cate_list:[],
        noDate: false,
      }
    },
    created () {
      this.cate()
    },
    mounted () {
      this.mescroll = new MeScroll(this.$refs.mescroll, { 
        up: {
          callback: this.upCallback
        }
      })
    },
    methods: {
      router (path) {
        this.$router.push(path)
      },
      upCallback (page) {
        mytrain(this.classifyNum,page.num, page.size).then((res) => {
          console.log(res)
          if (page.num == 1){
            this.lists = []
          }
          if(res.data == null){
            console.log(1)
            this.mescroll.endErr()
            return
          }
          this.$nextTick(() => {
            this.mescroll.endSuccess(res.data.data.list.length);
          })
          this.lists = this.lists.concat(res.data.data.list)
          if(this.lists.length == 0){
            this.noDate = true
          }
        }).catch((err) => {
          console.dir(err)
          this.mescroll.endErr()
        })
      },
      cate(){
        mytraincate().then((res) =>{
          console.log(res)
          this.cate_list=res.data.data.cate          
        }).catch((err) => {
          console.dir(err)
        })
      },
      classify (index, classify_name) {
        this.classifyNum = index
        this.is_mask = false
        this.classify_name = classify_name
        this.mescroll.resetUpScroll()
      }
    }
  }
</script>

<style lang="stylus" scoped>
.my-train
  background-color #f5f5f5
  min-height 100vh
  .mescroll
    position fixed
    top 0
    bottom 0
    height auto
    width 100vw
    overflow-x hidden
    .top-img
      float left
    .search
      float left
      width 92%
      margin-left 4%
      text-align center
      background-color #fff
      height 4.5rem
      line-height 4.5rem
      margin-top -2.25rem
      margin-bottom 1rem
      img
        display inline-block
        vertical-align middle
        width 1.6rem
      span
        display inline-block
        vertical-align middle
        font-size 1.3rem
        color #172F6D
        margin-left .5rem
  .classify
    padding 0 1.5rem
    line-height 4.5rem
    height 4.5rem
    color #333
    font-weight 500
    font-size 1.7rem
    position sticky
    border-bottom 1px solid #e6e6e6
    margin-bottom 1rem
    top 0
    background-color #fff
    text-align center
    .classify-img
      display inline-block
      vertical-align middle
      width .8rem
      position relative
      top -.2rem
  .content
    width 100%
    top 0
    left 0
    background-color #fff
    .list-item
      padding 1.5rem
      padding-bottom .5rem
      .item.active
        color #172F6D
        border 1px solid #172F6D
      .item
        border 1px solid #ccc
        color #999
        font-size 1.5rem
        padding .9rem 1.2rem
        float left
        margin-right 1rem
        margin-bottom 1rem
        height 1.5rem
        line-height 1.5rem
  .list
    width 100%
    background-color #f5f5f5
    .item
      display flex
      height 7rem
      background-color #fff
      padding 0 1.6rem
      border-bottom 1px solid #e6e6e6
      &:last-child
        border none
      .title
        font-size 1.5rem
        color #333
        overflow hidden
        white-space nowrap
        text-overflow ellipsis
        line-height 2rem
        height 2rem
        margin-bottom .4rem
        margin-top 1.5rem
        width 25rem
        margin-left -.8rem
      .time
        color #999
        font-size 1.2rem
        line-height 1.6rem
        height 1.6rem
      .left
        flex 3
      .right
        flex 1
        p
          width 100%
          text-align right
          margin-left 0
  .none
    img
      position absolute
      top 20.3rem
      width 7.25rem
      left 50%
      margin-left -3.625rem
    p
      color #666
      font-size 1.3rem
      text-align center
      position absolute
      width 100%
      top 32rem
</style>
